<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>坐标拾取</title>
    <link rel="stylesheet" href="/static/libs/layui/css/layui.css">
    <script src="/static/libs/jquery.min.js"></script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=fb4efe0c2c98af8f0f50e0a33cfb3879"></script>
    <style>
    #iMap {height: 560px; width: 690px;}
    .info {margin: 0 0 0 10px; width: 680px;} 
    </style>
</head>
<body onload="mapInit()">
<div id="iMap"></div>
<div class="info">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="text" id="lng" name="lng" value="" placeholder="请输入经度" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <input type="text" id="lat" name="lat" value="" placeholder="请输入纬度" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <button class="layui-btn" onclick="submit()">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script language="javascript">
    var mapObj;
    var lnglatXY;
     //初始化地图
    function mapInit() {
        var opt = {
            level: 10, //设置地图缩放级别
            center: new AMap.LngLat(120.1923,30.266846) //设置地图中心点
        }
        mapObj = new AMap.Map("iMap", opt);
        AMap.event.addListener(mapObj, 'click', getLnglat); //点击事件
    }

    function submit(){
        var lng = $("#lng").val();
        var lat = $("#lat").val();
        parent.$("#lng").val(lng);
        parent.$("#lat").val(lat);
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);//关闭弹出的子页面窗口
    }

    //鼠标点击，获取经纬度坐标
    function getLnglat(e) {
        mapObj.clearMap();
        var x = e.lnglat.getLng();
        var y = e.lnglat.getLat();
        document.getElementById('lng').value = x;
        document.getElementById('lat').value = y;
        lnglatXY = new AMap.LngLat(x, y);
        geocoder(); 
    } 
</script>
 </html>